package com.tanhua.server.controller;

import com.tanhua.domain.db.Settings;
import com.tanhua.server.service.SettingsService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     * 用户通用设置 - 通知设置的读取
     * 接口路径：GET/users/settings
     */
    @GetMapping("/settings")
    //读取通用设置
    public ResponseEntity<Object> settings() throws InvocationTargetException, IllegalAccessException {
        return settingsService.querySettings();
    }

    @PostMapping("/notifications/setting")
    //保存通用设置
    public ResponseEntity<Object> notifiSettings(@RequestBody Settings settings) throws InvocationTargetException, IllegalAccessException {
        return settingsService.notifiSettings(settings);
    }

    @PostMapping("/questions")
    //设置陌生人问题并保存
    public ResponseEntity<Object> questions(@RequestBody Map<String,String> params){
        String content = params.get("content");
        return settingsService.setQuestions(content);
    }

    @GetMapping("/blacklist")
    //分页显示黑名单
    public ResponseEntity<Object> blacklist(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10")Integer pageSize){
        return  settingsService.blackList(page,pageSize);
    }

    @DeleteMapping("/blacklist/{uid}")
    //删除黑名单
    public ResponseEntity<Object> deleteBlackList(@PathVariable("uid") Long blackUserId){
        return settingsService.deleteBlackList(blackUserId);
    }

    @PostMapping("/phone/sendVerificationCode")
    //修改手机号【验证码发送】
    public ResponseEntity<Object> sendVerificationCode(){
        return settingsService.sendVerificationCode();
    }

    @PostMapping("/phone/checkVerificationCode")
    //校验验证码
    public ResponseEntity<Object> checkVerificationCode(@RequestBody Map<String,String> params){
        String verificationCode = params.get("verificationCode");
        return settingsService.checkVerificationCode(verificationCode);
    }

    @PostMapping("/phone")
    //更新手机号
    public ResponseEntity<Object> phone(@RequestBody Map<String,String> params){
        String phone = params.get("phone");
        return settingsService.updatePhone(phone);
    }
}
